/**
 * @(#)RpgTestFacade.java	0.1 Nov 6, 2007
 *
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.wideskill.rpg4ejb3.sample.session.impl;

import javax.annotation.Resource;
import javax.ejb.Local;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.sql.DataSource;

import com.wideskill.rpg4ejb3.AS400EntityManager;
import com.wideskill.rpg4ejb3.RPGCallException;
import com.wideskill.rpg4ejb3.sample.entity.rpg.IRpgTest;
import com.wideskill.rpg4ejb3.sample.entity.rpg.impl.RpgTest;
import com.wideskill.rpg4ejb3.sample.entity.rpg.type.Services;
import com.wideskill.rpg4ejb3.sample.session.IRpgTestFacade;

/**
 * RpgTestFacade session.
 * 
 * @author: Luigi Scarpato <luigi.scarpato at Wideskill.Com>
 * 
 *	To run the test, you need to create META-INF/api.pcml file in the classpath
 *  Refer to PCML syntax for a detailed description of the language. 
 *  http://publib.boulder.ibm.com/infocenter/iadthelp/v7r0/index.jsp?topic=/com.ibm.etools.iseries.toolbox.doc/pcmlproc.htm
 */
@Stateless(name="RpgTestFacade")
@LocalBean
public class RpgTestFacade implements IRpgTestFacade {
	
	@Resource(name = "jdbc/__AS400")
	protected DataSource dataSource;

	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public String getRpgTestResponse(String iprgId) throws RPGCallException {
		
		IRpgTest rpgTest = new AS400EntityManager<RpgTest<Services>>(
				dataSource).call(new RpgTest<Services>(
						Services.TEST_RPG_SERVICE, "", "" ));
		
		if (!rpgTest.isExist()) 
			return null;
		
		return rpgTest.getResponse();
	}
}
